home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / bipl.zip / PROGS.ZIP / STARS.ICN < prev    next >
Text File  |  1992-12-30  |  3KB  |  93 lines

  1. ############################################################################
  2. #
  3. #    File:     stars.icn
  4. #
  5. #    Subject:  Program to display ``star'' field
  6. #
  7. #    Author:   Ralph E. Griswold
  8. #
  9. #    Date:     January 19, 1991
  10. #
  11. ###########################################################################
  12. #
  13. #  Requires:  co-expressions, ANSI terminal
  14. #
  15. ############################################################################
  16. #
  17. #  Links:  ansi
  18. #
  19. ############################################################################
  20. #
  21. #     This program display a random field of "stars" on an ANSI terminal.
  22. #  It displays stars at randomly chosen positions on the screen until
  23. #  the specified maximum number is reached. It then extinguishes existing
  24. #  stars and creates new ones for the specified steady-state time, after
  25. #  which the stars are extinguished, one by one.
  26. #
  27. #     The programming technique is worth noting. It is originally due to
  28. #  Steve Wampler.
  29. #
  30. #     The options are:
  31. #
  32. #    -m n    maximum number of stars, default 10.
  33. #
  34. #    -t n    length of steady-state time before stars are extinguished,
  35. #          default 50.
  36. #
  37. #    -s c    the character to be used for "stars", default *. If
  38. #          more than one character is given, only the first is
  39. #          used.
  40. #
  41. ############################################################################
  42. #
  43. #  Requires:  co-expressions, ANSI terminal
  44. #
  45. ############################################################################
  46. #
  47. #  Links:  ansi, options
  48. #
  49. ############################################################################
  50.  
  51. link ansi, options
  52.  
  53. procedure main(args)
  54.    local length, steady, star, opts, r, ran1, ran2
  55.  
  56.    opts := options(args,"m+t+s:")
  57.    length := \opts["m"] | 10
  58.    steady := \opts["t"] | 50
  59.    star := \opts["s"] | "*"
  60.    star := star[1]
  61.    r := 0
  62.  
  63.    ran1 := create 2(&random :=: r, |?(24 | 80), &random <-> r)
  64.    ran2 := ^ran1
  65.    clear()                # clear the screen
  66.    every 1 to length do            # start up the universe
  67.       place(ran1,star)
  68.    every 1 to steady do {        # steady state condition
  69.       place(ran2," ")            # clean up the beginning
  70.       place(ran1,star)            # create more
  71.       }
  72.    every 1 to length do            # and the universe dies
  73.       place(ran2," ")            # clean up the end
  74.    clear()                # clear the screen
  75.    home()                # home the cursor
  76. end
  77.  
  78. procedure clear()
  79.    ED()
  80.    return
  81. end
  82.  
  83. procedure home()
  84.    CUP(1,1)
  85.    return
  86. end
  87.  
  88. procedure place(e,s)
  89.    CUP(@e,@e)
  90.    writes(s)
  91.    return
  92. end
  93.